package com.ruoyi.web.controller.esm;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.esm.domain.FaEsmDevice;
import com.ruoyi.esm.service.IFaEsmDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产线Controller
 * 
 * @author colin
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/esm/device")
public class FaEsmDeviceController extends BaseController
{
    @Autowired
    private IFaEsmDeviceService faEsmDeviceService;

    /**
     * 查询产线列表
     */
    @PreAuthorize("@ss.hasPermi('esm:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaEsmDevice faEsmDevice)
    {
        startPage();
        List<FaEsmDevice> list = faEsmDeviceService.selectFaEsmDeviceList(faEsmDevice);
        return getDataTable(list);
    }

    /**
     * 导出产线列表
     */
    @PreAuthorize("@ss.hasPermi('esm:device:export')")
    @Log(title = "产线", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FaEsmDevice faEsmDevice)
    {
        List<FaEsmDevice> list = faEsmDeviceService.selectFaEsmDeviceList(faEsmDevice);
        ExcelUtil<FaEsmDevice> util = new ExcelUtil<FaEsmDevice>(FaEsmDevice.class);
        return util.exportExcel(list, "产线数据");
    }

    /**
     * 获取产线详细信息
     */
    @PreAuthorize("@ss.hasPermi('esm:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(faEsmDeviceService.selectFaEsmDeviceById(id));
    }

    /**
     * 新增产线
     */
    @PreAuthorize("@ss.hasPermi('esm:device:add')")
    @Log(title = "产线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaEsmDevice faEsmDevice)
    {
        return toAjax(faEsmDeviceService.insertFaEsmDevice(faEsmDevice));
    }

    /**
     * 修改产线
     */
    @PreAuthorize("@ss.hasPermi('esm:device:edit')")
    @Log(title = "产线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaEsmDevice faEsmDevice)
    {
        return toAjax(faEsmDeviceService.updateFaEsmDevice(faEsmDevice));
    }

    /**
     * 删除产线
     */
    @PreAuthorize("@ss.hasPermi('esm:device:remove')")
    @Log(title = "产线", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(faEsmDeviceService.deleteFaEsmDeviceByIds(ids));
    }
}
